package com.interview02;

import java.util.concurrent.TimeUnit;

/**
 * 同步代码块
 * 同步方法
 */
public class PresidentSynchronized {
    //3.添加一个自身的引用对象
    private static PresidentSynchronized president;
    //1.把构造方法私有化
    private PresidentSynchronized(){
        try { TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); }
        System.out.println("创建建国对象....");
    }


    //2.提供一个共有的静态的获取对象的方法
    public synchronized static PresidentSynchronized getInstance(){
        if (president == null) {
            president = new PresidentSynchronized();
        }
        return president;

    }
}
